package com.ruoyi.project.system.set.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.set.domain.FactorOpSymbolSet;
import com.ruoyi.project.system.set.service.IFactorOpSymbolSetService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 运算符Controller
 * 
 * @author ruoyi
 * @date 2021-12-29
 */
@Controller
@RequestMapping("/system/set")
public class FactorOpSymbolSetController extends BaseController
{
    private String prefix = "system/set";

    @Autowired
    private IFactorOpSymbolSetService factorOpSymbolSetService;

    @RequiresPermissions("system:set:view")
    @GetMapping()
    public String set()
    {
        return prefix + "/set";
    }

    /**
     * 查询运算符列表
     */
    @RequiresPermissions("system:set:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FactorOpSymbolSet factorOpSymbolSet)
    {
        startPage();
        List<FactorOpSymbolSet> list = factorOpSymbolSetService.selectFactorOpSymbolSetList(factorOpSymbolSet);
        return getDataTable(list);
    }

    /**
     * 导出运算符列表
     */
    @RequiresPermissions("system:set:export")
    @Log(title = "运算符", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FactorOpSymbolSet factorOpSymbolSet)
    {
        List<FactorOpSymbolSet> list = factorOpSymbolSetService.selectFactorOpSymbolSetList(factorOpSymbolSet);
        ExcelUtil<FactorOpSymbolSet> util = new ExcelUtil<FactorOpSymbolSet>(FactorOpSymbolSet.class);
        return util.exportExcel(list, "运算符数据");
    }

    /**
     * 新增运算符
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存运算符
     */
    @RequiresPermissions("system:set:add")
    @Log(title = "运算符", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FactorOpSymbolSet factorOpSymbolSet)
    {
        return toAjax(factorOpSymbolSetService.insertFactorOpSymbolSet(factorOpSymbolSet));
    }

    /**
     * 修改运算符
     */
    @RequiresPermissions("system:set:edit")
    @GetMapping("/edit/{symbolCd}")
    public String edit(@PathVariable("symbolCd") String symbolCd, ModelMap mmap)
    {
        FactorOpSymbolSet factorOpSymbolSet = factorOpSymbolSetService.selectFactorOpSymbolSetBySymbolCd(symbolCd);
        mmap.put("factorOpSymbolSet", factorOpSymbolSet);
        return prefix + "/edit";
    }

    /**
     * 修改保存运算符
     */
    @RequiresPermissions("system:set:edit")
    @Log(title = "运算符", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FactorOpSymbolSet factorOpSymbolSet)
    {
        return toAjax(factorOpSymbolSetService.updateFactorOpSymbolSet(factorOpSymbolSet));
    }

    /**
     * 删除运算符
     */
    @RequiresPermissions("system:set:remove")
    @Log(title = "运算符", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(factorOpSymbolSetService.deleteFactorOpSymbolSetBySymbolCds(ids));
    }
}
